package com.ct.controller.shipping;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ct.application.commons.vo.StatusRequest;
import com.ct.application.shipping.model.po.ChuanYuanZhengShuSavePO;
import com.ct.application.shipping.model.po.ChuanYuanZhengShuSearchPO;
import com.ct.application.shipping.model.vo.ChuanYuanZhengShuVO;
import com.ct.application.shipping.service.ChuanYuanZhengShuService;
import com.ct.commons.BaseController;
import com.ct.commons.annotation.ApiLog;
import com.ct.commons.annotation.HasAdmin;
import com.ct.commons.annotation.PermissionApi;
import com.ct.commons.aspect.limiter.AccessIpLimiter;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Objects;

/**
 * 船员证书配置
 * @author Auto Generator
 * @since 2023-08-16
 */
@RestController
@PermissionApi(title = "船员证书",path="/api/v1/chuanyuanzhengshu",code = "B1000",sorted = 9)
public class ChuanYuanZhengShuController extends BaseController {

    @Resource
    private ChuanYuanZhengShuService chuanYuanZhengShuService;


    /**
     * 查询船员证书列表
     * @return
     */
    @PostMapping("/chuanyuanzhengshu/listbiao")
    @PermissionApi(title = "查询船员证书列表",path="/api/v1/chuanyuanzhengshu/listbiao",code = "B1007",sorted = 7)
    public List<ChuanYuanZhengShuVO> findChuanYuanZhengShusBiao() {
        return chuanYuanZhengShuService.findChuanYuanZhengShusBiao();
    }

    /**
     * 查询船员证书列表
     * @param chuanYuanZhengShuSearchPO
     * @return
     */
    @PostMapping("/chuanyuanzhengshu/list")
    @PermissionApi(title = "查询船员证书列表",path="/api/v1/chuanyuanzhengshu/list",code = "B1001",sorted = 1)
    public Page<ChuanYuanZhengShuVO> findChuanYuanZhengShus(@Validated @RequestBody ChuanYuanZhengShuSearchPO chuanYuanZhengShuSearchPO) {
        return chuanYuanZhengShuService.findChuanYuanZhengShu(chuanYuanZhengShuSearchPO);
    }

    /**
     * 保存和更新
     *
     * @param savePO
     * @return
     */
    @PostMapping("/chuanyuanzhengshu/saveupdate")
    @ApiLog("船员证书保存和更新")
    @HasAdmin
    @AccessIpLimiter
    @PermissionApi(title = "船员证书保存和更新",path="/api/v1/chuanyuanzhengshu/saveupdate",code = "B1003",sorted = 3)
    public Boolean saveUpdateChuanYuanZhengShu(@Validated @RequestBody ChuanYuanZhengShuSavePO savePO) {
        if (Objects.nonNull(savePO.getId())){
            return chuanYuanZhengShuService.updateChuanYuanZhengShu(savePO);
        }else {
            return chuanYuanZhengShuService.saveChuanYuanZhengShu(savePO);
        }
    }

    /**
     * 根据id查询船员证书
     *
     * @param id
     * @return
     */
    @PostMapping("/chuanyuanzhengshu/get/{id}")
    @PermissionApi(title = "根据id查询船员证书",path="/api/v1/chuanyuanzhengshu/get/{id}",code = "B1004",sorted = 4)
    public ChuanYuanZhengShuVO getChuanYuanZhengShuById(@PathVariable("id") Long id) {
        return chuanYuanZhengShuService.getChuanYuanZhengShu(id);
    }


    /**
     * 根据id删除船员证书
     *
     * @param id
     * @return
     */
    @PostMapping("/chuanyuanzhengshu/del/{id}")
    @ApiLog("根据id删除船员证书")
    @HasAdmin
    @AccessIpLimiter
    @PermissionApi(title = "根据id删除船员证书",path="/api/v1/chuanyuanzhengshu/del/{id}",code = "B1005",sorted = 5)
    public Boolean delChuanYuanZhengShuById(@PathVariable("id") Long id) {
        return chuanYuanZhengShuService.delChuanYuanZhengShu(id);
    }

    /**
     * 修改状态
     *
     * @return
     */
    @PostMapping("/chuanyuanzhengshu/update/status")
    @ApiLog("船员证书修改状态")
    @HasAdmin
    @AccessIpLimiter
    @PermissionApi(title = "船员证书修改状态",path="/api/v1/chuanyuanzhengshu/update/status",code = "B1006",sorted = 6)
    public Boolean updateStatus(@Validated @RequestBody StatusRequest statusRequest) {
        return chuanYuanZhengShuService.updateStatus(statusRequest);
    }
}
